﻿@{
    Layout = "~/Views/Shared/_LayoutMain.cshtml";
    ViewBag.Title = "RunJieSuan";
}
<style type="text/css">
    .btnJs {
        background: #172c92;
        font-size: 18px;
        height: 40px;
        width: 200px;
        border-radius: 10px;
        color: #ffffff;
        text-align: center;
        line-height: 40px;
        cursor: pointer;
    }
    tr {
        height: 30px;
        line-height: 30px;
    }

    td {
        padding-left: 20px;
        padding-right: 20px;
    }

    th {
        padding-left: 20px;
        padding-right: 20px;
    }

    .kuai {
        margin-bottom: 20px;
    }
</style>
<div style="text-align:center;padding:20px;border-bottom:1px solid #808080;overflow:hidden;">
    <div style="float:left;">
        <div class="btnJs" onclick="jisuan()">计算</div>
    </div>
    <div style="float: left; margin-left:200px;">
        <div style="font-size:30px;">执行结算</div>
        <div style="padding-left:50px; color:red;">
            说明：计算的是当前所有未结算状态的记录
        </div>
    </div>
</div>
<div style="clear:both;"></div>
<div style="padding:50px;">
    <div id="table001">
    </div>
</div>

<script type="text/javascript">
    function jisuan() {
        var isPass = confirm("确认要结算吗？");
        if (isPass) {
            //$('#dg').datagrid({
            //    url: '/Consume/JiSuan',
            //    title: '消费结果列表清单',
            //    columns: [[
            //        { field: 'ct_TypeName', title: '消费类型名称' },
            //        { field: 'u_RealName', title: '付费人' },
            //        { field: 'totalPay', title: '总共支付金额' },
            //        { field: 'c_PersonTotalCount', title: '参与人数' },
            //        { field: 'AvgXiaoFei', title: '平均消费' }
            //    ]]
            //});

            $.ajax({
                type: "get",
                url: "/Consume/JiSuan",
                success: function (data) {
                    if (data == "0") {
                        var date = disptime().DateTime;
                        $("#table001").html("<div style=\"text-align:center;\"><h1 style=\"color:red;\">当前没有可计算的消费</h1>" + date + "</div>");
                        return;
                    }
                    var object = [];
                    var dataObject = $.parseJSON(data);

                    object.push("<div class=\"kuai\">")
                    //object.push("<div style=\"margin-bottom:5px;\">执行时间：" + createTime + "</div>");
                    object.push("<table border=\"1\" style=\"border-collapse:collapse;\">");
                    object.push("<tr>");
                    object.push("<th>消费类型名称</th>");
                    object.push("<th>付费人 </th>");
                    object.push("<th>总共支付金额</th>");
                    object.push("<th>参与人数</th>");
                    object.push("<th>平均消费 </th>");
                    object.push("<th>个人消费 </th>");
                    object.push("</tr>");
                    for (var i = 0; i < dataObject.length; i++) {
                        var item = dataObject[i];
                        object.push("<tr>");
                        object.push("<td>" + item.ct_TypeName + "</td>");
                        object.push("<td>" + item.u_RealName + "</td>");
                        object.push("<td>" + item.totalPay + "</td>");
                        object.push("<td>" + item.c_PersonTotalCount + "</td>");
                        object.push("<td>" + item.AvgXiaoFei + "</td>");
                        object.push("<td>" + item.personVal + "</td>");
                        object.push("</tr>");
                    }
                    object.push("</table>");
                    object.push("</div>");

                    //html赋值
                    var html = object.join('');
                    $("#table001").html(html);
                }
            });
        }
    }

    function disptime() {
        var date = new Date();
        var yyyy = date.getFullYear();//四位年份
        var month = date.getMonth() + 1;//月份 0-11
        var day = date.getDate();//日
        var HH = date.getHours();//时
        var minute = date.getMinutes();//分钟
        var second = date.getSeconds();//秒
        var milliseconds = date.getMilliseconds();//毫秒
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        if (HH < 10) {
            HH = "0" + HH;
        }
        if (minute < 10) {
            minute = "0" + minute;
        }
        if (second < 10) {
            second = "0" + second;
        }
        var time = yyyy + "-" + month + "-" + day + " " + HH + ":" + minute + ":" + second + " " + milliseconds;
        var timeTxt = yyyy + month + day + HH + minute + second;

        var time = {
            DateTime: time,
            TimeTxt: timeTxt
        }
        return time;
    }


</script>
